package com.breeze.components.core.util;

import cn.hutool.core.comparator.CompareUtil;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author breeze
 */
public class NumberUtils {

  public static boolean isNumberAndGt(Integer num1, Integer num2, int gt) {
    return isNumberAndGt(num1, gt) && isNumberAndGt(num2, gt);
  }

  public static boolean isNumberAndGt(Integer roleId, int gt) {
    return roleId != null && roleId > gt;
  }

  public static boolean isNumberAndNe(Integer status, int i) {
    return status != null && status != i;
  }

  public static boolean isNumberAndNe(Long status, long i) {
    return status != null && status != i;
  }

  public static boolean isNumberAndEq(Integer status, int i) {
    return status != null && status == i;
  }

  public static boolean isNumberAndGt(Double maxPrice, double v) {
    return maxPrice != null && maxPrice > v;
  }

  public static boolean isNumberAndGt(BigDecimal value, BigDecimal v) {
    return value != null && value.compareTo(v) > 0;
  }

  public static boolean isNumberAndGt(Long userId, Long i) {
    return userId != null && userId > i;
  }

  /** 参数1 大于等于 参数2, null作为小值 */
  public static boolean oneGeTwoNullLess(BigDecimal one, BigDecimal two) {
    return CompareUtil.compare(one, two) >= 0;
  }

  /** 参数1 大于等于 参数2, null作为大值 */
  public static boolean oneGeTwoNullGreater(BigDecimal one, BigDecimal two) {
    return CompareUtil.compare(one, two, true) >= 0;
  }

  /** 参数1 大于等于 参数2 */
  public static boolean oneGeTwo(BigDecimal one, BigDecimal two) {
    return one.compareTo(two) >= 0;
  }

  /** 参数1 大于 参数2 */
  public static boolean oneGtTwo(BigDecimal one, BigDecimal two) {
    //  - 返回值小于0表示调用方法的BigDecimal小于被比较的BigDecimal；
    //  - 返回值等于0表示调用方法的BigDecimal与被比较的BigDecimal相等；
    //  - 返回值大于0表示调用方法的BigDecimal大于被比较的BigDecimal。
    return one.compareTo(two) > 0;
  }

  /** 参数1 = 参数2 */
  public static boolean oneEqTwo(BigDecimal one, BigDecimal two) {
    return one.compareTo(two) == 0;
  }

  public static int maxIndex(List<Long> numbers) {
    if (numbers == null || numbers.isEmpty()) {
      return -1;
    }

    int maxIndex = 0;
    for (int i = 1; i < numbers.size(); i++) {
      if (numbers.get(i).compareTo(numbers.get(maxIndex)) > 0) {
        maxIndex = i;
      }
    }
    return maxIndex;
  }

  public static int minIndex(List<Long> numbers) {
    if (numbers == null || numbers.isEmpty()) {
      return -1;
    }

    int maxIndex = 0;
    for (int i = 1; i < numbers.size(); i++) {
      if (numbers.get(i).compareTo(numbers.get(maxIndex)) < 0) {
        maxIndex = i;
      }
    }
    return maxIndex;
  }
}
